function y = debt_update(oParams,f,c,lambda,equity,debt,bin_prob,recovery_value)
% Updates the debt value

% Variables:
% oParams		see readme
% f			rate of creative destruction
% c			coupon
% lambda	R&D intensity
% equity	equity value
% debt		debt value
% bin_prob	transition probabilities
% recovery_value recovery value

% Set parameters
	pbar = oParams.pbar;
	r = oParams.r;
	alpha = oParams.alpha;
	pvec = (0:pbar);
    
% Update equity value using the HJB equation
	y = (c + lambda .* (debt * bin_prob') + f * pvec .* [0 debt(1:end-1)])./(r + lambda + pvec * f);

% Default
	y(equity==0) = (1-alpha) * recovery_value(equity==0);

end
